package cn.flying.base.web.auth.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import cn.flying.base.web.auth.domain.SysSeq;
import cn.flying.base.web.auth.mapper.SysSeqMapper;

/**
 * @description: 序列号服务
 * @author: lvyong
 * @date: 2023年06月01日 12:40
 * @version: 1.0
 */
@Service
public class SysSeqService {

    @Resource
    private SysSeqMapper sysSeqMapper;

    @Transactional(rollbackFor = Exception.class)
    public String getSeq(String type) {
        SysSeq sysSeq = sysSeqMapper.getSysSeqNo(type);
        Long id;
        if (StringUtils.isEmpty(sysSeq.getCurSeqNo())) {
            id = sysSeq.getMinValue();
        } else {
            id = sysSeq.getCurSeqNo() + 1;
        }
        sysSeq.setCurSeqNo(id);

        sysSeqMapper.updateSysSeq(sysSeq);
        return String.valueOf(id);
    }
}
